
package com.wyzz.hr.bo.impl;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.lang.StringUtils;

import com.wyzz.hr.base.FileOperate;
import com.wyzz.hr.bo.IEmpAdditionalBo;
import com.wyzz.hr.dao.IEmpAdditionalDao;
import com.wyzz.hr.pojo.Employee;


public class EmpAdditionalBoImpl implements IEmpAdditionalBo {

	public EmpAdditionalBoImpl() {
	}

	public void saveResume(String resume1, String resume2, String empId) {
		Employee emp = (Employee) empAdditionalDao.loadObject(
				com.wyzz.hr.pojo.Employee.class, empId, null, new boolean[0]);
		if (emp == null)
			return;
		// if (StringUtils.isNotEmpty(resume1)) {
		// FileOperate
		// .deleteFile("sys.profile.file.path", emp.getEmpResume1());
		// emp.setEmpResume1(resume1);
		// }
		// if (StringUtils.isNotEmpty(resume2)) {
		// FileOperate
		// .deleteFile("sys.profile.file.path", emp.getEmpResume2());
		// emp.setEmpResume2(resume2);
		// }
		if (resume1 != null)
			emp.setEmpResume1(resume1);
		if (resume2 != null)
			emp.setEmpResume2(resume2);

		empAdditionalDao.saveOrupdate(emp);
	}

	public String deleteResume(String empId, int resumeSeq) {
		if (resumeSeq > 2 || resumeSeq < 1) {
			return "error";
		} else {
			String hql = (new StringBuilder()).append(
					"update Employee set empResume").append(resumeSeq).append(
					"=null where id='").append(empId).append("'").toString();
			empAdditionalDao.exeHql(hql);
			return "success";
		}
	}

	public void save(Employee employee, String empId) {
		Employee old = (Employee) empAdditionalDao.loadObject(
				com.wyzz.hr.pojo.Employee.class, empId, null, new boolean[0]);
		if (old == null)
			return;
		try {
			for (int i = 1; i <= 16; i++)
				BeanUtils.setProperty(old, (new StringBuilder()).append(
						"empAdditional").append(i).toString(), BeanUtils
						.getProperty(employee, (new StringBuilder()).append(
								"empAdditional").append(i).toString()));

			empAdditionalDao.saveOrupdate(old);
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}

	public IEmpAdditionalDao getEmpAdditionalDao() {
		return empAdditionalDao;
	}

	public void setEmpAdditionalDao(IEmpAdditionalDao empAdditionalDao) {
		this.empAdditionalDao = empAdditionalDao;
	}

	private IEmpAdditionalDao empAdditionalDao;
}
